<template>
  <!-- class="app-container" -->
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="合同编号" prop="contractNumber">
        <el-input v-model.trim="queryParams.contractNumber" placeholder="请输入合同编号" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="合同名称" prop="contractName">
        <el-input v-model.trim="queryParams.contractName" placeholder="请输入合同名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="合作达人id" prop="cooperationId">
        <el-input
          v-model.trim="queryParams.cooperationId"
          placeholder="请输入合作达人id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="合作达人名称" prop="cooperationGuru">
        <el-input v-model.trim="queryParams.cooperationGuru" placeholder="请输入合作达人名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button :icon="!isOpen ? 'el-icon-arrow-down' : 'el-icon-arrow-up'" size="mini"
          @click="shouqi">展开/收起</el-button>
      </el-form-item>
      <div v-if="isOpen">
        <el-form-item label="来源平台" prop="sourcePlatform">
          <el-input v-model.trim="queryParams.sourcePlatform" placeholder="请输入来源平台" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <!-- <el-form-item label="来源客户" prop="sourceCustomer">
          <el-input v-model.trim="queryParams.sourceCustomer" placeholder="请输入来源客户" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item> -->
        <!-- <el-form-item label="签约时间" prop="contractDate">
          <el-date-picker clearable v-model="queryParams.contractDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择签约时间">
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="报价金额" prop="quoteAmount">
          <el-input v-model.trim="queryParams.quoteAmount" placeholder="请输入报价金额" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="合同金额" prop="contractAmount">
          <el-input v-model.trim="queryParams.contractAmount" placeholder="请输入合同金额" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="合作周期开始时间" prop="cooperationStartDate">
          <el-date-picker clearable v-model="queryParams.cooperationStartDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合作周期开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合作周期结束时间" prop="cooperationEndDate">
          <el-date-picker clearable v-model="queryParams.cooperationEndDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合作周期结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同生效时间" prop="contractEffectiveDate">
          <el-date-picker clearable v-model="queryParams.contractEffectiveDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合同生效时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同签约时间" prop="contractSigningDate">
          <el-date-picker clearable v-model="queryParams.contractSigningDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择合同签约时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="经办人" prop="procedureOperator">
          <el-input v-model.trim="queryParams.procedureOperator" placeholder="请输入经办人" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="合同文件" prop="contractThumbnail">
          <el-input v-model.trim="queryParams.contractThumbnail" placeholder="请输入合同文件" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="逻辑删除" prop="isDelete">
          <el-input v-model.trim="queryParams.isDelete" placeholder="请输入逻辑删除" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
      </div>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['talent:BiTalentContract:add']" v-show="activePlatform == 'mine'">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-show="activePlatform == 'mine'" v-hasPermi="['talent:BiTalentContract:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-show="activePlatform == 'mine'" v-hasPermi="['talent:BiTalentContract:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['talent:BiTalentContract:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleSettlement"
          v-show="activePlatform == 'mine'">合同结案</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="BiTalentContractList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column width="150" label="合同编号" align="center" prop="contractNumber" />
      <el-table-column width="120" label="合同名称" align="center" prop="contractName" />
      <el-table-column width="120" label="合作达人id" align="center" prop="cooperationId" />
      <el-table-column width="120" label="合作达人名称" align="center" prop="cooperationGuru" />
      <el-table-column width="120" label="来源平台" align="center" prop="sourcePlatform" />
      <el-table-column width="120" label="来源机构" align="center" prop="sourceCustomer" />
      <!-- <el-table-column width="120" label="签约时间" align="center" prop="contractDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column> -->
      <el-table-column width="120" label="报价金额" align="center" prop="quoteAmount" />
      <el-table-column width="120" label="合同金额" align="center" prop="contractAmount" />
      <el-table-column width="120" label="周期开始时间" align="center" prop="cooperationStartDate">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.cooperationStartDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="周期结束时间" align="center" prop="cooperationEndDate">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.cooperationEndDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="合同生效时间" align="center" prop="contractEffectiveDate">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.contractEffectiveDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="合同签约时间" align="center" prop="contractSigningDate">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.contractSigningDate, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="经办人" align="center" prop="procedureOperator" />
      <el-table-column width="120" label="合同缩略图" align="center" prop="contractThumbnail">
        <template slot-scope="scope">
          <image-preview v-if="scope.row.contractThumbnailList" :src="scope.row.contractThumbnailList[0]" :width="30"
            :height="30" />
          <!-- <el-button size="mini" @click="downLoadFile(scope.row.contractThumbnail)" v-if="scope.row.contractThumbnail">
            下载
          </el-button> -->
          <span v-else></span>
        </template>
      </el-table-column>
      <!-- <el-table-column
        width="120"
        label="逻辑删除"
        align="center"
        prop="isDelete"
      /> -->
      <el-table-column width="120" label="备注" align="center" prop="remark" />
      <!-- <el-table-column
        width="120"
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['talent:BiTalentContract:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['talent:BiTalentContract:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改达人-合同对话框 -->
    <el-dialog :title="title" :visible.sync="open" v-if="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="10" class="mb8">
          <el-col :span="12">
            <!-- <el-form-item label="合同编号" prop="contractNumber">
              <el-input
                v-model.trim="form.contractNumber"
                placeholder="请输入合同编号"
              />
            </el-form-item> -->

            <!-- <el-form-item label="合作达人id" prop="cooperationId">
          <el-input
            v-model.trim="form.cooperationId"
            placeholder="请输入合作达人id"
          />
        </el-form-item> -->

            <el-form-item label="来源平台" prop="sourcePlatform">
              <!-- <el-input v-model.trim="form.sourcePlatform" placeholder="请输入来源平台" /> -->
              <el-select v-model="form.sourcePlatform" placeholder="平台名称" clearable>
                <el-option v-for="dict in dict.type.sys_sample_name" :key="dict.value" :label="dict.label"
                  :value="dict.value" />
              </el-select>
            </el-form-item>
            <!--<el-form-item label="来源客户" prop="sourceCustomer">
          <el-input
            v-model.trim="form.sourceCustomer"
            placeholder="请输入来源客户"
          />
        </el-form-item>
        <el-form-item label="签约时间" prop="contractDate">
          <el-date-picker
            clearable
            v-model="form.contractDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择签约时间"
          >
          </el-date-picker>
        </el-form-item> -->
            <el-form-item label="报价金额" prop="quoteAmount">
              <el-input v-model.trim="form.quoteAmount" placeholder="请输入报价金额" />
            </el-form-item>
            <el-form-item label="合作周期" prop="dataDate">
              <!-- <el-date-picker
          clearable
          v-model="queryParams.dataDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="支付日期"
        >
        </el-date-picker> -->
              <el-date-picker v-model="value2" type="daterange" align="right" unlink-panels range-separator="-"
                start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" @change="changeTime"
                size="mini">
              </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="合作周期开始时间" prop="cooperationStartDate">
              <el-date-picker
                clearable
                v-model="form.cooperationStartDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择合作周期开始时间"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item label="合作周期结束时间" prop="cooperationEndDate">
              <el-date-picker
                clearable
                v-model="form.cooperationEndDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择合作周期结束时间"
              >
              </el-date-picker>
            </el-form-item> -->
            <el-form-item label="合同生效时间" prop="contractEffectiveDate">
              <el-date-picker clearable v-model="form.contractEffectiveDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择合同生效时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="合同签约时间" prop="contractSigningDate">
              <el-date-picker clearable v-model="form.contractSigningDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择合同签约时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="来源机构" prop="sourceCustomer">
              <el-input v-model.trim="form.sourceCustomer" placeholder="请输入来源机构" />
            </el-form-item>
          </el-col>
          <!-- <el-form-item label="经办人" prop="procedureOperator">
          <el-input
            v-model.trim="form.procedureOperator"
            placeholder="请输入经办人"
          />
        </el-form-item> -->
          <el-col :span="12">
            <el-form-item label="合同名称" prop="contractName">
              <el-input v-model.trim="form.contractName" placeholder="请输入合同名称" />
            </el-form-item>
            <el-form-item label="合作达人名称" prop="cooperationGuru">
              <!-- <el-input v-model.trim="form.cooperationGuru" placeholder="请输入合作达人名称" /> -->
              <el-select v-model="form.cooperationGuru" placeholder="达人昵称" clearable filterable @change="testNickname">
                <el-option v-for="(dict, index) in NicknameList" :key="index" :label="dict.xhsNickname" :value="dict" />
              </el-select>
            </el-form-item>
            <el-form-item label="合同金额" prop="contractAmount">
              <el-input v-model.trim="form.contractAmount" placeholder="请输入合同金额" />
            </el-form-item>
            <!-- <el-form-item label="合同文件" prop="contractThumbnail">


              <el-upload ref="upload" :action="Upload.url" :headers="Upload.headers" :limit="limit"
                :on-exceed="handleExceed" :on-success="handlePictureSuccessPic" :before-upload="beforeAvatarUpload"
                :on-preview="handlePictureCardPreview" :file-list="fileLi" :on-change="changeFile1">
                <el-button size="small" type="primary">导入文件</el-button>

              </el-upload>
            </el-form-item> -->
            <el-form-item label="合同图片" label-width="120px" prop="logoUrl">
              <!-- <el-upload :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card" :limit="limit"
                                                                                                                                    :on-exceed="handleExceed" :on-success="handlePictureSuccess" :before-upload="beforeAvatarUpload"
                                                                                                                                    :on-preview="handlePictureCardPreview" :file-list="fileList" :on-change="changeFile2">
                                                                                                                                    <i class="el-icon-plus"></i>
                                                                                                                                </el-upload>
                                                                                                                                <el-dialog :visible.sync="dialogVisible">
                                                                                                                                    <img width="100%" v-if="imageUrl" :src="imageUrl" alt="">
                                                                                                                                                                    </el-dialog> -->
              <el-upload ref="uploadlogourl" :action="imgUpload.url" :headers="imgUpload.headers" list-type="picture-card"
                :on-change="changelogourl" :file-list="filelogourl" multiple :on-success="uploadlogourl"
                :on-remove="Removelogourl" :on-preview="handlePictureCardPreview">
                <i class="el-icon-plus"></i>
              </el-upload>
              <div id="preview" @paste="handlelogourl">
                <span><i class="el-icon-s-opportunity" style="color: #fb894c"></i>点击此处 将截图按Ctrl+V 粘贴至此处</span>
              </div>
              <el-dialog title="点击图片预览" width="400px" v-if="dialogVisible" :visible.sync="dialogVisible" append-to-body>
                <!-- <img width="100%" v-if="imageUrl" :src="imageUrl" alt=""> -->
                <image-preview v-if="imageUrl" :src="imageUrl" :width="300" :height="300" />
              </el-dialog>
            </el-form-item>
          </el-col>
          <!-- <el-form-item label="逻辑删除" prop="isDelete">
          <el-input v-model.trim="form.isDelete" placeholder="请输入逻辑删除" />
        </el-form-item> -->
          <!-- <el-form-item label="备注" prop="remark">
          <el-input v-model.trim="form.remark" placeholder="请输入备注" />
        </el-form-item> -->
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { selectTalentNamelist } from "@/api/live/BiLiveOrder";
//--------导入token
import { getToken } from "@/utils/auth";
import {
  listBiTalentContract,
  getBiTalentContract,
  delBiTalentContract,
  addBiTalentContract,
  updateBiTalentContract,
  cooperativeSettlement
} from "@/api/talent/BiTalentContract";
import moment from "moment";
export default {
  name: "BiTalentContract",
  dicts: [
    "sys_product_qudao",
    "sys_sample_status",
    "sys_sample_sf",
    "sys_one_zero",
    "sys_sample_day",
    "sys_sample_time",
    "sys_sample_name",
    "sys_sample_cj",
    "sys_jst_sample_sf",
  ],
  props: {
    row: {
      type: Object,
      default: () => { },
    },
    activePlatform: {
      type: String,
      default: null,
    },
  },
  data() {
    return {
      NicknameList: [],
      list: [],
      dialogVisible: false,
      imageUrl: '',
      filelogourl: [],
      upload_list: [], //提交的图片数组
      imgUpload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },

      fileLi: [],
      Upload: {
        // 设置上传的请求头部
        headers: {
          Authorization: "Bearer " + getToken(),
        },
        // 图片上传的方法地址:
        url: process.env.VUE_APP_BASE_API + "/common/upload",
      },
      logoUrl: "",
      logoUrlYL: "",

      upload_logourl: [], //提交的图片数组
      //图片相对路径
      // picurl: '',
      // //图片地址
      // picUrl: '',
      //logo相对路径
      // logoUrl: '',
      pjtUrl: process.env.VUE_APP_BASE_API,
      // 图片数量限制
      limit: 2,
      isOpen: false,
      inputValue: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 达人-合同表格数据
      BiTalentContractList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractNumber: null,
        contractName: null,
        cooperationId: null,
        cooperationGuru: null,
        sourcePlatform: null,
        sourceCustomer: null,
        contractDate: null,
        quoteAmount: null,
        contractAmount: null,
        cooperationStartDate: null,
        cooperationEndDate: null,
        contractEffectiveDate: null,
        contractSigningDate: null,
        procedureOperator: null,
        contractThumbnail: null,
        isDelete: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      value2: [], // 默认选中最近30天
    };
  },
  watch: {
    row: {
      handler: function (newnew, oldold) {
        this.queryParams.cooperationId = this.row.platformId;
        this.getList();
      },
      deep: true,
      immediate: true,
    },
    activePlatform: {
      handler: function (newnew, oldold) {
        this.queryParams.viewLabel = this.activePlatform;
        this.getList();
      },
      deep: true,
      immediate: true,
    },
  },
  created() {
    this.getList();
    this.getNickname();
  },
  methods: {
    // 打开加载层
    openLoading() {
      this.$modal.loading("正在加载，请稍候！");
    },
    getNickname(key) {
      this.NicknameList = [];
      this.openLoading();
      selectTalentNamelist().then((response) => {
        this.$modal.closeLoading();
        response.forEach((element) => {
          this.NicknameList.push({
            xhsNickname: element.talentName,
            platformId: element.talentId,
          });
        });
      });
      // listSample({ xhsNickname: key }).then((response) => {
      //   // console.log(JSON.stringify(response));
      //   if (response.rows.length > 0) {
      //     response.rows.forEach((element) => {
      //       this.NicknameList.push({
      //         xhsNickname: element.xhsNickname,
      //         platformId: element.platformId,
      //       });
      //       this.$forceUpdate();
      //     });
      //   }
      // });
    },
    handleSettlement() {
      if (this.list.length != 1) {
        this.$modal.msgError("请只选择一条数据")
        return
      }
      let obj = {
        contractNumber: this.list[0].contractNumber
      }
      cooperativeSettlement(obj).then(response => {
        if (response.code == 200) {
          this.$modal.msgSuccess(response.msg)
          this.getList()
        }
      })
    },
    changeTime() {
      // console.log(JSON.stringify(this.value2));
      let m1 = moment(this.value2[0]).format("YYYY-MM-DD");
      let m2 = moment(this.value2[1]).format("YYYY-MM-DD");
      // console.log(JSON.stringify(m1));
      // console.log(JSON.stringify(m2));
      this.form.cooperationStartDate = m1;
      this.form.cooperationEndDate = m2;
      // this.getList();
      // this.queryParams.startDate = m1;
      // this.queryParams.endDate = m2;
    },
    //搜索栏展示与收起
    shouqi() {
      // console.log(1);
      this.isOpen = !this.isOpen;
    },
    /** 查询达人-合同列表 */
    getList() {
      this.loading = true;
      listBiTalentContract(this.queryParams).then((response) => {
        this.BiTalentContractList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      // this.upload_list = []
      this.upload_list = []
      this.filelogourl = []
      this.value2 = [];
      this.form = {
        id: null,
        contractNumber: null,
        contractName: null,
        cooperationId: null,
        cooperationGuru: null,
        sourcePlatform: null,
        sourceCustomer: null,
        contractDate: null,
        quoteAmount: null,
        contractAmount: null,
        cooperationStartDate: null,
        createBy: null,
        cooperationEndDate: null,
        contractEffectiveDate: null,
        contractSigningDate: null,
        procedureOperator: null,
        contractThumbnail: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelete: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.list = selection.map((item) => item);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加达人-合同";
    },
    testNickname(key) {
      console.log(JSON.stringify(key));
      this.form.cooperationGuru = key.xhsNickname;
      this.form.cooperationId = key.platformId;
      this.$forceUpdate();
      // listSample({ xhsNickname: key }).then((response) => {
      //   console.log(JSON.stringify(response));
      // });
    },
    /** 提交按钮 */
    submitForm() {
      if (!this.form.cooperationStartDate || !this.form.cooperationEndDate) {
        this.$modal.msgError("请选择合作周期");
        return;
      }

      if (!this.form.cooperationId) {
        this.form.cooperationId = this.row.platformId;
      }
      this.form.contractThumbnail = ''; // 注：重要(用于添加到数据库)，加的是这一行

      this.form.contractThumbnailList = this.upload_list; // 注：重要(用于添加到数据库)，加的是这一行
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateBiTalentContract(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBiTalentContract(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
          this.upload_list = []
          this.filelogourl = []
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除达人-合同编号为"' + ids + '"的数据项？')
        .then(function () {
          return delBiTalentContract(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "talent/BiTalentContract/export",
        {
          ...this.queryParams,
        },
        `BiTalentContract_${new Date().getTime()}.xlsx`
      );
    },


    // 打开加载层
    openUploadLoading() {
      this.$modal.loading("正在导入，请稍候！");
    },
    //文件导入成功回传

    handlePictureSuccessPic(res, file) {
      this.$refs.upload.clearFiles();
      console.log(JSON.stringify(res));
      //设置图片访问路径 （url 后台传过来的的上传地址）
      // this.picUrl = file.response.url;
      // const url = file.response.fileName;
      this.logoUrl = file.response.url;
      console.log(JSON.stringify(this.file));
      if (res.code == 200) {
        // this.dialogVisible = false;
        this.$modal.closeLoading();
        // this.$modal.msgSuccess(res.msg);
        // if (res.msg == "操作成功") {
        this.$modal.msgSuccess("导入成功");
        // } else {
        //   this.$modal.msgError(res.msg);
        // }
        // this.getList();
        // return true
      } else {
        this.$modal.msgError(res.msg);
        // this.dialogVisible = true;
        // this.$message.msgError('该颜色未在字典定义')
        return;
      }
    },

    //图片上传前的相关判断
    beforeAvatarUpload(file) {
      // const isJPG = file.type == 'image/jpeg' || file.type == 'image/png';
      const isLt2M = file.size / 1024 / 1024 < 100;
      // if (!isJPG) {
      //     this.$message.error('上传头像图片只能是 JPG/PNG 格式!');
      // }
      if (!isLt2M) {
        this.$message.error("上传文件大小不能超过 100MB!");
      }
      this.openUploadLoading();
      return isLt2M;
    },

    // 文件个数超出
    handleExceed() {
      this.$modal.msgError(`上传链接文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传文件让第二次覆盖第一的文件
    changeFile1(file, fileList) {
      if (fileList.length > 1) {
        this.fileLi = fileList.slice(-1);

        // this.fileList = [fileList[fileList.length - 1]]//这一步，是 展示最后一次选择文件
      }
      // this.fileSpecial = fileList;
    },
    //质检报告下载
    downLoadFile(value) {
      if (!value) {
        this.$modal.msgError("该合同没有上传附件，请选择至少一个文件！");
        return;
      }
      console.log(JSON.stringify(value));
      window.location.href = value;
    },



    //logo图片
    handlelogourl(event) {
      const items = (event.clipboardData || window.clipboardData).items;
      let file = null;
      if (!items || items.length === 0) {
        this.$message.error("当前浏览器不支持本地");
        return;
      }
      // 搜索剪切板items
      for (let i = 0; i < items.length; i++) {
        if (items[i].type.indexOf("image") !== -1) {
          file = items[i].getAsFile();
          break;
        }
      }
      if (!file) {
        this.$message.error("粘贴内容非图片");
        return;
      }
      // if (this.upload_list.length >= this.limit) {
      //   this.$message.error(`上传文件不能超过 ${this.limit} 个!`); // 图片购买数量超出
      //   return;
      // }
      this.$refs.uploadlogourl.handleStart(file); // 将粘贴过来的图片加入预上传队列
      this.$refs.uploadlogourl.submit(); // 提交图片上传队列
    },
    //上传
    changelogourl(file, fileList) {
      // this.fileList = fileList
      // console.log("成功", file, fileList);
      // console.log(JSON.stringify(file));
      // console.log(JSON.stringify(fileList));
      // if (fileList.length > 3) {
      //   this.filelogourl = fileList.slice(-1);
      //   this.upload_list = this.upload_list.slice(-1);
      // }
      // console.log(JSON.stringify(this.upload_list));
      // console.log(JSON.stringify("filelogourl", this.filelogourl));
      // this.filelogourl = fileList;
      // if (this.filelogourl.length > 2) {
      //   this.filelogourl.shift();
      //   this.filelogourl.push(file.response.fileName);
      // } else {
      //   this.filelogourl.push(file.response.fileName);
      // }
    },
    Removelogourl(file, fileList) {
      console.log(JSON.stringify(file));
      console.log(JSON.stringify(this.upload_list));
      // this.logoUrl = "";
      // this.filelogourl = fileList;

      var index = this.upload_list.indexOf(file.url.replace(process.env.VUE_APP_BASE_API, ''));
      console.log(index);
      this.upload_list.splice(index, 1);
      console.log(JSON.stringify(this.upload_list));
    },
    //图片预览
    handlePictureCardPreview(file) {
      // this.picUrl = file.url
      this.imageUrl = file.url;
      this.dialogVisible = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getBiTalentContract(id).then((response) => {
        this.form = response.data;
        this.value2 = [
          this.form.cooperationStartDate,
          this.form.cooperationEndDate,
        ];
        this.logoUrl = this.form.contractThumbnail;
        if (!this.form.contractThumbnailList) {
          this.upload_list = []
          this.filelogourl = []
        } else {
          this.form.contractThumbnailList = this.form.contractThumbnailList.filter(item => item !== "")
          this.upload_list = this.form.contractThumbnailList
          this.form.contractThumbnailList.forEach(item => {
            this.filelogourl.push({ url: process.env.VUE_APP_BASE_API + item })
          })
        }
        this.open = true;
        this.title = "修改达人-合同";
      });
    },
    uploadlogourl(res, file, fileList) {

      // if (this.upload_list.length > 2) {
      //   this.upload_list.shift();
      //   this.upload_list.push(file.response.fileName);
      // } else {
      //   this.upload_list.push(file.response.fileName);
      // }
      this.upload_list.push(file.response.fileName);
      // this.filelogourl.push({ url: file.response.url })
      console.log(JSON.stringify(this.upload_list));
    },
  },
};
</script>
